<template>
  <view class="change-request-page">
    <view class="page-header">
      <text class="page-title">停车场信息编辑</text>
      <text class="page-desc">编辑停车场信息并提交变更申请</text>
    </view>

    <!-- 申请类型选择 -->
    <view class="request-type-section">
      <text class="section-title">申请类型</text>
      <view class="type-options">
        <view 
          v-for="type in requestTypes" 
          :key="type.value"
          class="type-option"
          :class="{ active: selectedType === type.value }"
          @click="selectType(type.value)"
        >
          <text class="type-name">{{ type.name }}</text>
          <text class="type-desc">{{ type.desc }}</text>
        </view>
      </view>
    </view>

    <!-- 停用申请 -->
    <view v-if="selectedType === 'close_dates'" class="form-section">
      <text class="section-title">停用申请确认</text>
      <view class="close-warning">
        <view class="warning-icon">⚠️</view>
        <view class="warning-content">
          <text class="warning-title">重要提醒</text>
          <text class="warning-desc">停用后，停车场将无法接受新的预订订单，现有订单不受影响。</text>
          <text class="warning-desc">如需重新启用，可以提交启用申请。</text>
        </view>
      </view>
    </view>

    <!-- 启用申请 -->
    <view v-if="selectedType === 'activate'" class="form-section">
      <text class="section-title">启用申请确认</text>
      <view class="activate-info">
        <view class="info-icon">✅</view>
        <view class="info-content">
          <text class="info-title">申请启用停车场</text>
          <text class="info-desc">启用后，停车场将可以接受新的预订订单。</text>
          <text class="info-desc">请确保停车场已准备好正常运营。</text>
        </view>
      </view>
    </view>

    <!-- 统一的停车场信息编辑 -->
    <view v-if="selectedType === 'modify_comprehensive'" class="form-section">
      <text class="section-title">停车场信息编辑</text>
      
      <!-- 基本信息 -->
      <view class="info-group">
        <text class="group-title">基本信息</text>
        <view class="info-form">
          <view class="form-item">
            <text class="label">停车场名称</text>
            <input 
              v-model="editData.name" 
              class="info-input"
              :placeholder="currentParkingLot?.name || '请输入停车场名称'"
            />
          </view>
          <view class="form-item">
            <text class="label">联系电话</text>
            <input 
              v-model="editData.contact_phone" 
              class="info-input"
              :placeholder="currentParkingLot?.contact_phone || '请输入联系电话'"
            />
          </view>
          <view class="form-item">
            <text class="label">备用电话</text>
            <input 
              v-model="editData.backup_phone" 
              class="info-input"
              :placeholder="currentParkingLot?.backup_phone || '请输入备用电话'"
            />
          </view>
          <view class="form-item">
            <text class="label">停车场分类</text>
            <picker 
              :range="categories"
              range-key="name"
              :value="getCategoryIndex(editData.category_id)"
              @change="selectCategory"
            >
              <view class="picker-display">
                {{ getCategoryName(editData.category_id) }}
              </view>
            </picker>
          </view>
          <view class="form-item">
            <text class="label">详细地址</text>
            <input 
              v-model="editData.address" 
              class="info-input"
              :placeholder="currentParkingLot?.address || '请输入详细地址'"
            />
          </view>
          <view class="form-item">
            <text class="label">描述信息</text>
            <textarea 
              v-model="editData.description" 
              class="info-textarea"
              :placeholder="currentParkingLot?.description || '请输入描述信息'"
            />
          </view>
        </view>
      </view>

      <!-- 车位信息 -->
      <view class="info-group">
        <text class="group-title">车位信息</text>
        <view class="spaces-form">
          <view class="form-item">
            <text class="label">当前车位数</text>
            <view class="current-value">{{ currentParkingLot?.total_spaces || 0 }} 个</view>
          </view>
          <view class="form-item">
            <text class="label">申请修改为</text>
            <input 
              v-model.number="editData.total_spaces" 
              type="number" 
              class="spaces-input"
              :placeholder="String(currentParkingLot?.total_spaces || 0)"
            />
            <text class="unit">个</text>
          </view>
        </view>
      </view>

      <!-- 距离信息 -->
      <view class="info-group">
        <text class="group-title">距离信息</text>
        <view class="distance-form">
          <view class="form-item">
            <text class="label">距离机场(公里)</text>
            <input 
              v-model.number="editData.airport_distance_km" 
              type="number" 
              class="distance-input"
              :placeholder="String(currentParkingLot?.airport_distance_km || 0)"
            />
            <text class="unit">km</text>
          </view>
          <view class="form-item">
            <text class="label">距离高铁站(公里)</text>
            <input 
              v-model.number="editData.station_distance_km" 
              type="number" 
              class="distance-input"
              :placeholder="String(currentParkingLot?.station_distance_km || 0)"
            />
            <text class="unit">km</text>
          </view>
          <view class="form-item">
            <text class="label">摆渡时间(分钟)</text>
            <input 
              v-model.number="editData.shuttle_time_minutes" 
              type="number" 
              class="distance-input"
              :placeholder="String(currentParkingLot?.shuttle_time_minutes || 0)"
            />
            <text class="unit">分钟</text>
          </view>
        </view>
      </view>

      <!-- 服务设施 -->
      <view class="info-group">
        <text class="group-title">服务设施</text>
        <view class="facilities-grid">
          <view 
            v-for="facility in facilityOptions" 
            :key="facility.key"
            class="facility-item"
            :class="{ active: editData.service_facilities.includes(facility.key) }"
            @click="toggleFacility(facility.key)"
          >
            <text class="facility-icon">{{ facility.icon }}</text>
            <text class="facility-name">{{ facility.name }}</text>
          </view>
        </view>
      </view>

      <!-- 价格规则 -->
      <view class="info-group">
        <text class="group-title">价格规则设置</text>
        
        <!-- 计费模式选择 -->
        <view class="billing-mode-section">
          <text class="sub-title">计费模式</text>
          <view class="mode-options">
            <view 
              class="mode-option"
              :class="{ active: editData.price_rules.type === 'cumulative_daily' }"
              @click="editData.price_rules.type = 'cumulative_daily'"
            >
              <text>自然天计费</text>
            </view>
            <view 
              class="mode-option"
              :class="{ active: editData.price_rules.type === 'rolling_24h' }"
              @click="editData.price_rules.type = 'rolling_24h'"
            >
              <text>24小时计费</text>
            </view>
          </view>
        </view>

        <!-- 室内外分别定价开关 -->
        <view class="indoor-outdoor-section">
          <view class="switch-item">
            <text class="sub-title">室内外分别定价</text>
            <switch 
              :checked="editData.price_rules.indoor_outdoor_enabled"
              @change="onIndoorOutdoorToggle"
              color="#007aff"
            />
          </view>
        </view>

        <!-- 统一定价模式 -->
        <view v-if="!editData.price_rules.indoor_outdoor_enabled" class="unified-pricing">
          <text class="sub-title">累计价格设置（1-7天）</text>
          <view class="daily-prices-grid">
            <view v-for="day in 7" :key="day" class="price-item">
              <text class="price-label">第{{ day }}天累计</text>
              <input 
                v-model.number="editData.price_rules.daily_prices[`day_${day}`]" 
                type="number" 
                class="price-input"
                :placeholder="`第${day}天累计费用`"
              />
              <text class="price-unit">元</text>
            </view>
          </view>
          
          <view class="after-7-section">
            <text class="sub-title">第8天起每日价格</text>
            <view class="price-item">
              <text class="price-label">每日价格</text>
              <input 
                v-model.number="editData.price_rules.daily_price_after_7" 
                type="number" 
                class="price-input"
                placeholder="第8天起每日价格"
              />
              <text class="price-unit">元/天</text>
            </view>
          </view>
        </view>

        <!-- 室内外分别定价模式 -->
        <view v-if="editData.price_rules.indoor_outdoor_enabled" class="separate-pricing">
          <!-- 室内价格 -->
          <view class="indoor-pricing">
            <text class="sub-title">室内停车价格</text>
            <view class="daily-prices-grid">
              <view v-for="day in 7" :key="`indoor-${day}`" class="price-item">
                <text class="price-label">第{{ day }}天累计</text>
                <input 
                  v-model.number="editData.price_rules.indoor_prices.daily_prices[`day_${day}`]" 
                  type="number" 
                  class="price-input"
                  :placeholder="`第${day}天累计费用`"
                />
                <text class="price-unit">元</text>
              </view>
            </view>
            <view class="after-7-section">
              <view class="price-item">
                <text class="price-label">第8天起每日价格</text>
                <input 
                  v-model.number="editData.price_rules.indoor_prices.daily_price_after_7" 
                  type="number" 
                  class="price-input"
                  placeholder="第8天起每日价格"
                />
                <text class="price-unit">元/天</text>
              </view>
            </view>
          </view>

          <!-- 室外价格 -->
          <view class="outdoor-pricing">
            <text class="sub-title">室外停车价格</text>
            <view class="daily-prices-grid">
              <view v-for="day in 7" :key="`outdoor-${day}`" class="price-item">
                <text class="price-label">第{{ day }}天累计</text>
                <input 
                  v-model.number="editData.price_rules.outdoor_prices.daily_prices[`day_${day}`]" 
                  type="number" 
                  class="price-input"
                  :placeholder="`第${day}天累计费用`"
                />
                <text class="price-unit">元</text>
              </view>
            </view>
            <view class="after-7-section">
              <view class="price-item">
                <text class="price-label">第8天起每日价格</text>
                <input 
                  v-model.number="editData.price_rules.outdoor_prices.daily_price_after_7" 
                  type="number" 
                  class="price-input"
                  placeholder="第8天起每日价格"
                />
                <text class="price-unit">元/天</text>
              </view>
            </view>
          </view>
        </view>

        <view class="price-tip">
          <text>💡 提示：价格设置与管理端保持一致，支持室内外分别定价</text>
        </view>
      </view>

      <!-- 营业资料 -->
      <view class="info-group">
        <text class="group-title">营业资料管理</text>
        
        <!-- 营业执照 -->
        <view class="document-section">
          <text class="sub-title">营业执照</text>
          <view class="document-upload">
            <view 
              v-if="!editData.business_documents.business_license"
              class="upload-placeholder"
              @click="chooseBusinessDocument('business_license')"
            >
              <view class="upload-icon">📄</view>
              <text class="upload-text">点击上传营业执照</text>
              <text class="upload-tip">支持 jpg/png/pdf 格式</text>
            </view>
            <view v-else class="document-preview">
              <view class="document-info">
                <text class="document-name">{{ editData.business_documents.business_license.filename }}</text>
                <text class="document-size">{{ formatFileSize(editData.business_documents.business_license.size) }}</text>
              </view>
              <view class="document-actions">
                <button 
                  class="action-btn view-btn"
                  @click="previewDocument(editData.business_documents.business_license.url)"
                >
                  查看
                </button>
                <button 
                  class="action-btn remove-btn"
                  @click="removeBusinessDocument('business_license')"
                >
                  删除
                </button>
              </view>
            </view>
          </view>
        </view>

        <!-- 法人身份证 -->
        <view class="document-section">
          <text class="sub-title">法人身份证</text>
          <view class="document-upload">
            <view 
              v-if="!editData.business_documents.legal_id || editData.business_documents.legal_id.length === 0"
              class="upload-placeholder"
              @click="chooseBusinessDocument('legal_id')"
            >
              <view class="upload-icon">🆔</view>
              <text class="upload-text">点击上传法人身份证</text>
              <text class="upload-tip">可上传正反面，最多2张</text>
            </view>
            <view v-else class="document-list">
              <view 
                v-for="(doc, index) in editData.business_documents.legal_id" 
                :key="index"
                class="document-preview"
              >
                <view class="document-info">
                  <text class="document-name">{{ doc.filename }}</text>
                  <text class="document-size">{{ formatFileSize(doc.size) }}</text>
                </view>
                <view class="document-actions">
                  <button 
                    class="action-btn view-btn"
                    @click="previewDocument(doc.url)"
                  >
                    查看
                  </button>
                  <button 
                    class="action-btn remove-btn"
                    @click="removeBusinessDocumentFromList('legal_id', index)"
                  >
                    删除
                  </button>
                </view>
              </view>
              <view 
                v-if="editData.business_documents.legal_id.length < 2"
                class="add-more-btn"
                @click="chooseBusinessDocument('legal_id')"
              >
                <text>+ 添加更多</text>
              </view>
            </view>
          </view>
        </view>

        <!-- 场地租赁合同 -->
        <view class="document-section">
          <text class="sub-title">场地租赁合同</text>
          <view class="document-upload">
            <view 
              v-if="!editData.business_documents.lease_contract || editData.business_documents.lease_contract.length === 0"
              class="upload-placeholder"
              @click="chooseBusinessDocument('lease_contract')"
            >
              <view class="upload-icon">📃</view>
              <text class="upload-text">点击上传租赁合同</text>
              <text class="upload-tip">最多上传3个文件</text>
            </view>
            <view v-else class="document-list">
              <view 
                v-for="(doc, index) in editData.business_documents.lease_contract" 
                :key="index"
                class="document-preview"
              >
                <view class="document-info">
                  <text class="document-name">{{ doc.filename }}</text>
                  <text class="document-size">{{ formatFileSize(doc.size) }}</text>
                </view>
                <view class="document-actions">
                  <button 
                    class="action-btn view-btn"
                    @click="previewDocument(doc.url)"
                  >
                    查看
                  </button>
                  <button 
                    class="action-btn remove-btn"
                    @click="removeBusinessDocumentFromList('lease_contract', index)"
                  >
                    删除
                  </button>
                </view>
              </view>
              <view 
                v-if="editData.business_documents.lease_contract.length < 3"
                class="add-more-btn"
                @click="chooseBusinessDocument('lease_contract')"
              >
                <text>+ 添加更多</text>
              </view>
            </view>
          </view>
        </view>

        <view class="business-tip">
          <text>💡 提示：营业资料用于合规认证，请上传清晰完整的文件</text>
        </view>
      </view>

      <!-- 图片信息 -->
      <view class="info-group">
        <text class="group-title">停车场图片</text>
        <view class="image-upload-section">
          <text class="upload-tip">当前图片（点击可删除）</text>
          <view class="current-images" v-if="currentImages.length > 0">
            <view 
              v-for="(image, index) in currentImages" 
              :key="'current-' + index" 
              class="image-item"
            >
              <image :src="getFullImageUrl(image)" class="preview-image" />
              <button class="remove-image-btn" @click="removeCurrentImage(index)">删除</button>
            </view>
          </view>
          
          <text class="upload-tip">添加新图片</text>
          <view class="image-list">
            <view 
              v-for="(image, index) in editData.new_images" 
              :key="'new-' + index" 
              class="image-item"
            >
              <image :src="getFullImageUrl(image)" class="preview-image" />
              <button class="remove-image-btn" @click="removeNewImage(index)">删除</button>
            </view>
            <view class="upload-btn" @click="chooseImage" v-if="getTotalImageCount() < 6">
              <text>+</text>
            </view>
          </view>
          <text class="image-limit-tip">最多上传6张图片，当前已有 {{ getTotalImageCount() }} 张</text>
        </view>
      </view>
    </view>

    <!-- 申请原因 -->
    <view v-if="selectedType !== ''" class="form-section">
      <text class="section-title">申请原因</text>
      <textarea 
        v-model="reason" 
        class="reason-textarea"
        placeholder="请详细说明申请原因"
      />
    </view>

    <!-- 提交按钮 -->
    <view class="submit-section">
      <button 
        class="submit-btn" 
        :disabled="!canSubmit || submitting"
        @click="submitRequest"
      >
        {{ submitting ? '提交中...' : '提交申请' }}
      </button>
    </view>

    <!-- 申请记录 -->
    <view class="history-section">
      <text class="section-title">申请记录</text>
      <view v-if="requestHistory.length === 0" class="empty-history">
        <text>暂无申请记录</text>
      </view>
      <view v-else class="history-list">
        <view 
          v-for="record in requestHistory" 
          :key="record.id" 
          class="history-item"
        >
          <view class="history-header">
            <text class="history-type">{{ getRequestTypeText(record.request_type) }}</text>
            <text class="history-status" :class="record.status">
              {{ getStatusText(record.status) }}
            </text>
          </view>
          <text class="history-reason">{{ record.reason }}</text>
          <text class="history-time">{{ formatDate(record.created_at) }}</text>
          <text v-if="record.admin_comment" class="admin-comment">
            管理员意见：{{ record.admin_comment }}
          </text>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'
import {
  submitChangeRequest,
  getOperatorChangeRequests,
  submitCloseDatesRequest,
  submitModifySpacesRequest,
  submitModifyImagesRequest,
  submitModifyInfoRequest,
  submitComprehensiveChangeRequest
} from '../../api/changeRequest.js'
import { get, BASE_URL } from '../../utils/request.js'

// 响应式数据
const selectedType = ref('')
const reason = ref('')
const submitting = ref(false)
const currentParkingLot = ref(null)
const requestHistory = ref([])

// 申请类型选项（动态计算）
const requestTypes = computed(() => {
  const types = [
    {
      value: 'modify_comprehensive',
      name: '停车场信息编辑',
      desc: '统一编辑停车场基本信息、车位数和图片'
    }
  ]

  // 根据停车场状态添加启用/停用申请
  if (currentParkingLot.value) {
    if (currentParkingLot.value.status === 'approved') {
      // 如果是启用状态，显示停用申请
      types.push({
        value: 'close_dates',
        name: '停用申请',
        desc: '申请停用停车场（停车场将无法接受新订单）'
      })
    } else if (currentParkingLot.value.status === 'inactive') {
      // 如果是停用状态，显示启用申请
      types.push({
        value: 'activate',
        name: '启用申请',
        desc: '申请启用停车场（停车场将可以接受新订单）'
      })
    }
  }

  return types
})

// 关闭日期相关
const closedDates = ref([])

// 车位数修改相关
const newSpaces = ref(0)

// 图片修改相关
const newImages = ref([])

// 基本信息修改相关
const newInfo = ref({
  name: '',
  contact_phone: '',
  description: ''
})

// 统一编辑数据
const editData = ref({
  name: '',
  contact_phone: '',
  backup_phone: '', // 新增：备用电话
  address: '',
  description: '',
  total_spaces: 0,
  airport_distance_km: 0, // 新增：机场距离
  station_distance_km: 0, // 新增：高铁站距离
  shuttle_time_minutes: 0, // 新增：摆渡时间
  category_id: null, // 新增：分类
  service_facilities: [], // 新增：服务设施
  // 价格规则（与管理端保持一致的JSON结构）
  price_rules: {
    type: 'cumulative_daily', // 'cumulative_daily' | 'rolling_24h'
    indoor_outdoor_enabled: false,
    daily_prices: {
      day_1: 0,
      day_2: 0,
      day_3: 0,
      day_4: 0,
      day_5: 0,
      day_6: 0,
      day_7: 0
    },
    daily_price_after_7: 0,
    indoor_prices: {
      daily_prices: {
        day_1: 0,
        day_2: 0,
        day_3: 0,
        day_4: 0,
        day_5: 0,
        day_6: 0,
        day_7: 0
      },
      daily_price_after_7: 0
    },
    outdoor_prices: {
      daily_prices: {
        day_1: 0,
        day_2: 0,
        day_3: 0,
        day_4: 0,
        day_5: 0,
        day_6: 0,
        day_7: 0
      },
      daily_price_after_7: 0
    }
  },
  // 营业资料（与管理端保持一致的JSON结构）
  business_documents: {
    business_license: null, // 营业执照
    legal_id: [], // 法人身份证（最多2张）
    lease_contract: [] // 场地租赁合同（最多3张）
  },
  new_images: []
})

// 当前停车场图片
const currentImages = ref([])

// 当前营业执照图片
const currentLicenseImages = ref([])

// 停车场分类数据
const categories = ref([])

// 服务设施选项
const facilityOptions = ref([
  { key: 'has_charging_pile', name: '充电桩', icon: '⚡' },
  { key: 'is_24_hours', name: '24小时', icon: '🕰️' },
  { key: 'has_camera', name: '监控', icon: '📹' },
  { key: 'is_indoor', name: '室内', icon: '🏠' },
  { key: 'has_24h_shuttle', name: '24H接送', icon: '🚐' },
  { key: 'has_staff_on_duty', name: '专人值守', icon: '👨‍💼' },
  { key: 'has_surveillance', name: '监控', icon: '📺' },
  { key: 'has_7_seat_shuttle', name: '7座接送', icon: '🚗' },
  { key: 'has_5_seat_shuttle', name: '5座接送', icon: '🚙' },
  { key: 'has_parking_invoice', name: '发票', icon: '📎' },
  { key: 'walking_distance', name: '步行即达', icon: '🚶' }
])

// 计算属性
const canSubmit = computed(() => {
  if (!selectedType.value || !reason.value.trim()) {
    return false
  }
  
  switch (selectedType.value) {
    case 'close_dates':
      return true // 停用申请只需要填写原因即可
    case 'activate':
      return true // 启用申请只需要填写原因即可
    case 'modify_comprehensive':
      // 统一编辑模式：检查是否有任何字段被修改
      return hasAnyChanges()
    case 'modify_spaces':
      return newSpaces.value > 0
    case 'modify_images':
      return newImages.value.length > 0
    case 'modify_info':
      return newInfo.value.name || newInfo.value.contact_phone || newInfo.value.description
    default:
      return false
  }
})

// 方法
const selectType = (type) => {
  selectedType.value = type
  resetFormData()
}

// 解析JSON数据的帮助函数
const parseJsonField = (field, fallback) => {
  if (!field) return fallback
  if (typeof field === 'string') {
    try {
      return JSON.parse(field)
    } catch (e) {
      console.error('解析JSON字段失败:', e)
      return fallback
    }
  }
  return field
}

const resetFormData = () => {
  closedDates.value = []
  newSpaces.value = 0
  newImages.value = []
  newInfo.value = {
    name: '',
    contact_phone: '',
    description: ''
  }
  // 重置统一编辑数据
  if (currentParkingLot.value) {
    // 解析所有可能是JSON字符串的字段
    const serviceFacilities = parseJsonField(currentParkingLot.value.service_facilities, [])
    const priceRules = parseJsonField(currentParkingLot.value.price_rules, null)
    const businessDocuments = parseJsonField(currentParkingLot.value.business_documents, {})
    
    editData.value = {
      name: currentParkingLot.value.name || '',
      contact_phone: currentParkingLot.value.contact_phone || '',
      backup_phone: currentParkingLot.value.backup_phone || '',
      address: currentParkingLot.value.address || '',
      description: currentParkingLot.value.description || '',
      total_spaces: currentParkingLot.value.total_spaces || 0,
      airport_distance_km: currentParkingLot.value.airport_distance_km || 0,
      station_distance_km: currentParkingLot.value.station_distance_km || 0,
      shuttle_time_minutes: currentParkingLot.value.shuttle_time_minutes || 0,
      category_id: currentParkingLot.value.category_id || null,
      service_facilities: [...serviceFacilities],
      // 价格规则（使用解析后的price_rules或默认值）
      price_rules: priceRules ? 
        JSON.parse(JSON.stringify(priceRules)) : {
          type: 'cumulative_daily',
          indoor_outdoor_enabled: false,
          daily_prices: {
            day_1: 0, day_2: 0, day_3: 0, day_4: 0,
            day_5: 0, day_6: 0, day_7: 0
          },
          daily_price_after_7: 0,
          indoor_prices: {
            daily_prices: {
              day_1: 0, day_2: 0, day_3: 0, day_4: 0,
              day_5: 0, day_6: 0, day_7: 0
            },
            daily_price_after_7: 0
          },
          outdoor_prices: {
            daily_prices: {
              day_1: 0, day_2: 0, day_3: 0, day_4: 0,
              day_5: 0, day_6: 0, day_7: 0
            },
            daily_price_after_7: 0
          }
        },
      // 营业资料（使用解析后的business_documents或默认值）
      business_documents: Object.keys(businessDocuments).length > 0 ? 
        JSON.parse(JSON.stringify(businessDocuments)) : {
          business_license: null,
          legal_id: [],
          lease_contract: []
        },
      new_images: []
    }
  }
}

const addClosedDate = () => {
  closedDates.value.push({
    date: '',
    reason: ''
  })
}

const updateDate = (index, event) => {
  closedDates.value[index].date = event.detail.value
}

const removeDate = (index) => {
  closedDates.value.splice(index, 1)
}

// 检查是否有任何更改
const hasAnyChanges = () => {
  if (!currentParkingLot.value) return false
  
  const original = currentParkingLot.value
  const current = editData.value
  
  // 检查基本信息是否有变化
  if (current.name !== original.name ||
      current.contact_phone !== original.contact_phone ||
      current.backup_phone !== (original.backup_phone || '') ||
      current.address !== original.address ||
      current.description !== original.description ||
      current.total_spaces !== original.total_spaces) {
    return true
  }
  
  // 检查距离信息是否有变化
  if (current.airport_distance_km !== (original.airport_distance_km || 0) ||
      current.station_distance_km !== (original.station_distance_km || 0) ||
      current.shuttle_time_minutes !== (original.shuttle_time_minutes || 0)) {
    return true
  }
  
  // 检查分类是否有变化
  if (current.category_id !== original.category_id) {
    return true
  }
  
  // 检查服务设施是否有变化
  const originalFacilities = JSON.stringify(original.service_facilities || [])
  const currentFacilities = JSON.stringify(current.service_facilities || [])
  if (originalFacilities !== currentFacilities) {
    return true
  }
  
  // 检查价格规则是否有变化
  const originalPriceRules = JSON.stringify(original.price_rules || {})
  const currentPriceRules = JSON.stringify(current.price_rules || {})
  if (originalPriceRules !== currentPriceRules) {
    return true
  }
  
  // 检查营业资料是否有变化
  const originalBusinessDocs = JSON.stringify(original.business_documents || {})
  const currentBusinessDocs = JSON.stringify(current.business_documents || {})
  if (originalBusinessDocs !== currentBusinessDocs) {
    return true
  }
  
  // 检查是否有新图片或删除了图片
  if (current.new_images.length > 0 || currentImages.value.length !== (original.images?.length || 0)) {
    return true
  }
  
  // 该检查已在上面的business_documents中包含
  
  return false
}

// 获取完整图片URL
const getFullImageUrl = (imageUrl) => {
  if (!imageUrl) return ''
  if (imageUrl.startsWith('http')) return imageUrl
  return `${BASE_URL}${imageUrl}`
}

// 获取总图片数量
const getTotalImageCount = () => {
  return currentImages.value.length + editData.value.new_images.length
}

// 删除当前图片
const removeCurrentImage = (index) => {
  currentImages.value.splice(index, 1)
}

// 删除新图片
const removeNewImage = (index) => {
  editData.value.new_images.splice(index, 1)
}

// 营业执照图片相关方法
const getTotalLicenseImageCount = () => {
  return currentLicenseImages.value.length + editData.value.new_license_images.length
}

const removeCurrentLicenseImage = (index) => {
  currentLicenseImages.value.splice(index, 1)
}

const removeNewLicenseImage = (index) => {
  editData.value.new_license_images.splice(index, 1)
}

const chooseLicenseImage = () => {
  const maxCount = 3 - getTotalLicenseImageCount()
  if (maxCount <= 0) {
    uni.showToast({
      title: '最多只能上传3张营业执照图片',
      icon: 'none'
    })
    return
  }
  
  uni.chooseImage({
    count: maxCount,
    success: (res) => {
      uni.showLoading({
        title: '上传中...'
      })
      uploadLicenseImages(res.tempFilePaths)
    }
  })
}

// 上传营业执照图片
const uploadLicenseImages = async (tempFilePaths) => {
  try {
    const uploadPromises = tempFilePaths.map(filePath => uploadSingleImage(filePath))
    const results = await Promise.all(uploadPromises)
    
    const successUrls = results.filter(result => result.success).map(result => result.url)
    
    if (successUrls.length > 0) {
      editData.value.new_license_images.push(...successUrls)
      uni.showToast({
        title: `成功上传${successUrls.length}张营业执照图片`,
        icon: 'success'
      })
    } else {
      uni.showToast({
        title: '营业执照图片上传失败',
        icon: 'none'
      })
    }
  } catch (error) {
    console.error('上传营业执照图片失败:', error)
    uni.showToast({
      title: '上传失败',
      icon: 'none'
    })
  } finally {
    uni.hideLoading()
  }
}

const chooseImage = () => {
  const maxCount = 6 - getTotalImageCount()
  if (maxCount <= 0) {
    uni.showToast({
      title: '最多只能上传6张图片',
      icon: 'none'
    })
    return
  }
  
  uni.chooseImage({
    count: maxCount,
    success: (res) => {
      // 显示上传进度
      uni.showLoading({
        title: '上传中...'
      })
      
      // 逐个上传图片
      uploadImages(res.tempFilePaths)
    }
  })
}

// 上传图片函数
const uploadImages = async (tempFilePaths) => {
  try {
    const uploadPromises = tempFilePaths.map(filePath => uploadSingleImage(filePath))
    const results = await Promise.all(uploadPromises)
    
    // 过滤出成功上传的图片URL
    const successUrls = results.filter(result => result.success).map(result => result.url)
    
    if (successUrls.length > 0) {
      // 根据当前申请类型处理图片
      if (selectedType.value === 'modify_comprehensive') {
        editData.value.new_images.push(...successUrls)
      } else {
        // 兼容原有的图片修改申请
        newImages.value.push(...successUrls)
      }
      
      uni.showToast({
        title: `成功上传${successUrls.length}张图片`,
        icon: 'success'
      })
    } else {
      uni.showToast({
        title: '图片上传失败',
        icon: 'none'
      })
    }
  } catch (error) {
    console.error('上传图片失败:', error)
    uni.showToast({
      title: '上传失败',
      icon: 'none'
    })
  } finally {
    uni.hideLoading()
  }
}

// 上传单张图片
const uploadSingleImage = (filePath) => {
  return new Promise((resolve, reject) => {
    console.log('=== 开始上传图片 ===')
    console.log('文件路径:', filePath)
    const uploadUrl = `${BASE_URL}/api/parking-operator/upload-image`
    console.log('上传URL:', uploadUrl)
    console.log('Token:', uni.getStorageSync('token'))
    
    uni.uploadFile({
      url: uploadUrl,
      filePath: filePath,
      name: 'file',
      header: {
        'Authorization': `Bearer ${uni.getStorageSync('token')}`
      },
      success: (res) => {
        console.log('=== 上传响应 ===')
        console.log('状态码:', res.statusCode)
        console.log('响应数据:', res.data)
        console.log('响应头:', res.header)
        
        try {
          const data = JSON.parse(res.data)
          console.log('解析后的数据:', data)
          
          if (data.success) {
            console.log('上传成功，文件URL:', data.data.url)
            resolve({
              success: true,
              url: data.data.url
            })
          } else {
            console.error('服务器返回失败:', data)
            resolve({
              success: false,
              error: data.message
            })
          }
        } catch (error) {
          console.error('解析JSON失败:', error)
          console.error('原始响应数据:', res.data)
          resolve({
            success: false,
            error: '解析响应失败: ' + error.message
          })
        }
      },
      fail: (error) => {
        console.error('=== 上传请求失败 ===')
        console.error('错误详情:', error)
        resolve({
          success: false,
          error: error.errMsg || '上传请求失败'
        })
      }
    })
  })
}

const removeImage = (index) => {
  newImages.value.splice(index, 1)
}

// 室内外定价开关处理
const onIndoorOutdoorToggle = (event) => {
  const enabled = event.detail.value
  editData.value.price_rules.indoor_outdoor_enabled = enabled
  
  if (enabled) {
    // 启用室内外分别定价时，将当前统一价格复制到室内价格
    Object.assign(editData.value.price_rules.indoor_prices, {
      daily_prices: { ...editData.value.price_rules.daily_prices },
      daily_price_after_7: editData.value.price_rules.daily_price_after_7
    })
    
    // 设置默认的室外价格（比室内价格稍低）
    Object.assign(editData.value.price_rules.outdoor_prices, {
      daily_prices: {
        day_1: 0,
        day_2: Math.max(0, (editData.value.price_rules.daily_prices.day_2 || 60) - 10),
        day_3: Math.max(0, (editData.value.price_rules.daily_prices.day_3 || 80) - 10),
        day_4: Math.max(0, (editData.value.price_rules.daily_prices.day_4 || 100) - 10),
        day_5: Math.max(0, (editData.value.price_rules.daily_prices.day_5 || 120) - 10),
        day_6: Math.max(0, (editData.value.price_rules.daily_prices.day_6 || 140) - 10),
        day_7: Math.max(0, (editData.value.price_rules.daily_prices.day_7 || 140) - 10)
      },
      daily_price_after_7: Math.max(0, (editData.value.price_rules.daily_price_after_7 || 20) - 2)
    })
  }
}

// 选择营业资料文件
const chooseBusinessDocument = (documentType) => {
  uni.chooseImage({
    count: documentType === 'legal_id' ? 2 : documentType === 'lease_contract' ? 3 : 1,
    sizeType: ['original', 'compressed'],
    sourceType: ['album', 'camera'],
    success: (res) => {
      const tempFilePaths = res.tempFilePaths
      uploadBusinessDocuments(tempFilePaths, documentType)
    },
    fail: (err) => {
      console.error('选择文件失败:', err)
      uni.showToast({
        title: '选择文件失败',
        icon: 'none'
      })
    }
  })
}

// 上传营业资料文件
const uploadBusinessDocuments = async (filePaths, documentType) => {
  try {
    uni.showLoading({ title: '上传中...' })
    
    // 使用已导入的BASE_URL
    
    for (let filePath of filePaths) {
      const uploadResult = await new Promise((resolve, reject) => {
        uni.uploadFile({
          url: `${BASE_URL}/api/parking-operator/upload-image`,
          filePath: filePath,
          name: 'file',
          header: {
            'Authorization': `Bearer ${uni.getStorageSync('token')}`
          },
          success: (res) => {
            console.log('营业资料上传响应:', res)
            try {
              const data = JSON.parse(res.data)
              console.log('解析后的数据:', data)
              
              if (data.success) {
                console.log('上传成功，文件URL:', data.data.url)
                resolve({
                  url: data.data.url,
                  filename: data.data.filename || data.data.originalName || '文件',
                  size: data.data.size || 0
                })
              } else {
                console.error('服务器返回失败:', data)
                reject(new Error(data.message || '上传失败'))
              }
            } catch (error) {
              console.error('解析响应数据失败:', error)
              reject(new Error('解析响应数据失败'))
            }
          },
          fail: reject
        })
      })
      
      // 根据文件类型存储
      if (documentType === 'business_license') {
        editData.value.business_documents.business_license = uploadResult
      } else if (documentType === 'legal_id') {
        if (!editData.value.business_documents.legal_id) {
          editData.value.business_documents.legal_id = []
        }
        editData.value.business_documents.legal_id.push(uploadResult)
      } else if (documentType === 'lease_contract') {
        if (!editData.value.business_documents.lease_contract) {
          editData.value.business_documents.lease_contract = []
        }
        editData.value.business_documents.lease_contract.push(uploadResult)
      }
    }
    
    uni.hideLoading()
    uni.showToast({
      title: '上传成功',
      icon: 'success'
    })
  } catch (error) {
    uni.hideLoading()
    console.error('上传文件失败:', error)
    uni.showToast({
      title: error.message || '上传失败',
      icon: 'none'
    })
  }
}

// 删除营业资料文件
const removeBusinessDocument = (documentType) => {
  editData.value.business_documents[documentType] = null
}

// 从列表中删除营业资料文件
const removeBusinessDocumentFromList = (documentType, index) => {
  editData.value.business_documents[documentType].splice(index, 1)
}

// 预览文件
const previewDocument = (url) => {
  uni.previewImage({
    urls: [url],
    current: url
  })
}

// 格式化文件大小
const formatFileSize = (size) => {
  if (!size) return '0 KB'
  const units = ['B', 'KB', 'MB', 'GB']
  let index = 0
  while (size >= 1024 && index < units.length - 1) {
    size /= 1024
    index++
  }
  return `${size.toFixed(1)} ${units[index]}`
}

const submitRequest = async () => {
  if (!canSubmit.value) return
  
  try {
    submitting.value = true
    
    let response
    const parkingLotId = currentParkingLot.value?.id
    
    switch (selectedType.value) {
      case 'close_dates':
        // 停用申请
        response = await submitChangeRequest({
          parking_lot_id: parkingLotId,
          request_type: 'close_dates',
          request_data: { action: 'deactivate' },
          reason: reason.value
        })
        break
      case 'activate':
        // 启用申请
        response = await submitChangeRequest({
          parking_lot_id: parkingLotId,
          request_type: 'activate',
          request_data: { action: 'activate' },
          reason: reason.value
        })
        break
      case 'modify_comprehensive':
        // 统一编辑申请
        response = await submitComprehensiveChangeRequest(parkingLotId, editData.value, currentImages.value, reason.value)
        break
      case 'modify_spaces':
        response = await submitModifySpacesRequest(parkingLotId, newSpaces.value, reason.value)
        break
      case 'modify_images':
        response = await submitModifyImagesRequest(parkingLotId, newImages.value, reason.value)
        break
      case 'modify_info':
        response = await submitModifyInfoRequest(parkingLotId, newInfo.value, reason.value)
        break
    }
    
    if (response.success) {
      uni.showToast({
        title: '申请提交成功',
        icon: 'success'
      })
      
      // 重置表单
      selectedType.value = ''
      reason.value = ''
      resetFormData()
      
      // 刷新申请记录
      await loadRequestHistory()
    } else {
      uni.showToast({
        title: response.message || '提交失败',
        icon: 'none'
      })
    }
  } catch (error) {
    console.error('提交申请失败:', error)
    uni.showToast({
      title: '提交失败',
      icon: 'none'
    })
  } finally {
    submitting.value = false
  }
}

const loadParkingLotInfo = async () => {
  try {
    const response = await get('/api/parking-operator/parking-lot')
    
    if (response.success) {
      currentParkingLot.value = response.data
      
      console.log('停车场数据:', response.data)
      console.log('图片数据 images:', response.data.images)
      console.log('图片数据 image_urls:', response.data.image_urls)
      
      // 初始化当前图片 - 检查两种可能的字段名
      let images = []
      if (response.data.image_urls) {
        // 如果是JSON字符串，需要解析
        if (typeof response.data.image_urls === 'string') {
          try {
            images = JSON.parse(response.data.image_urls)
          } catch (e) {
            console.error('解析图片URL失败:', e)
            images = []
          }
        } else if (Array.isArray(response.data.image_urls)) {
          images = response.data.image_urls
        }
      } else if (response.data.images) {
        images = response.data.images
      }
      
      console.log('解析后的图片数组:', images)
      currentImages.value = Array.isArray(images) ? [...images] : []
      
      // 解析服务设施数据
      let serviceFacilities = []
      if (response.data.service_facilities) {
        if (typeof response.data.service_facilities === 'string') {
          try {
            serviceFacilities = JSON.parse(response.data.service_facilities)
            console.log('解析服务设施JSON:', serviceFacilities)
          } catch (e) {
            console.error('解析服务设施失败:', e)
            serviceFacilities = []
          }
        } else if (Array.isArray(response.data.service_facilities)) {
          serviceFacilities = response.data.service_facilities
        }
      }
      console.log('最终服务设施数组:', serviceFacilities)
      
      // 解析价格规则数据
      let priceRules = null
      if (response.data.price_rules) {
        if (typeof response.data.price_rules === 'string') {
          try {
            priceRules = JSON.parse(response.data.price_rules)
            console.log('解析价格规则JSON:', priceRules)
          } catch (e) {
            console.error('解析价格规则失败:', e)
            priceRules = null
          }
        } else if (typeof response.data.price_rules === 'object') {
          priceRules = response.data.price_rules
        }
      }
      console.log('最终价格规则对象:', priceRules)
      
      // 解析营业资料数据
      let businessDocuments = {}
      if (response.data.business_documents) {
        if (typeof response.data.business_documents === 'string') {
          try {
            businessDocuments = JSON.parse(response.data.business_documents)
            console.log('解析营业资料JSON:', businessDocuments)
          } catch (e) {
            console.error('解析营业资料失败:', e)
            businessDocuments = {}
          }
        } else if (typeof response.data.business_documents === 'object') {
          businessDocuments = response.data.business_documents
        }
      }
      console.log('最终营业资料对象:', businessDocuments)
      
      // 初始化营业执照图片
      let licenseImages = []
      if (response.data.business_documents) {
        if (typeof response.data.business_documents === 'string') {
          try {
            licenseImages = JSON.parse(response.data.business_documents)
          } catch (e) {
            console.error('解析营业执照图片失败:', e)
            licenseImages = []
          }
        } else if (Array.isArray(response.data.business_documents)) {
          licenseImages = response.data.business_documents
        }
      }
      currentLicenseImages.value = Array.isArray(licenseImages) ? [...licenseImages] : []
      
      // 初始化编辑数据
      editData.value = {
        name: response.data.name || '',
        contact_phone: response.data.contact_phone || '',
        backup_phone: response.data.backup_phone || '',
        address: response.data.address || '',
        description: response.data.description || '',
        total_spaces: response.data.total_spaces || 0,
        airport_distance_km: response.data.airport_distance_km || 0,
        station_distance_km: response.data.station_distance_km || 0,
        shuttle_time_minutes: response.data.shuttle_time_minutes || 0,
        category_id: response.data.category_id || null,
        service_facilities: [...serviceFacilities],
        // 价格规则（使用解析后的price_rules或默认值）
        price_rules: priceRules ? 
          JSON.parse(JSON.stringify(priceRules)) : {
            type: 'cumulative_daily',
            indoor_outdoor_enabled: false,
            daily_prices: {
              day_1: 0, day_2: 0, day_3: 0, day_4: 0,
              day_5: 0, day_6: 0, day_7: 0
            },
            daily_price_after_7: 0,
            indoor_prices: {
              daily_prices: {
                day_1: 0, day_2: 0, day_3: 0, day_4: 0,
                day_5: 0, day_6: 0, day_7: 0
              },
              daily_price_after_7: 0
            },
            outdoor_prices: {
              daily_prices: {
                day_1: 0, day_2: 0, day_3: 0, day_4: 0,
                day_5: 0, day_6: 0, day_7: 0
              },
              daily_price_after_7: 0
            }
          },
        // 营业资料（使用解析后的business_documents或默认值）
        business_documents: Object.keys(businessDocuments).length > 0 ? 
          JSON.parse(JSON.stringify(businessDocuments)) : {
            business_license: null,
            legal_id: [],
            lease_contract: []
          },
        new_images: []
      }
    }
  } catch (error) {
    console.error('加载停车场信息失败:', error)
    uni.showToast({
      title: error.message || '获取停车场信息失败',
      icon: 'none'
    })
  }
}

const loadRequestHistory = async () => {
  try {
    if (!currentParkingLot.value?.id) return
    
    const response = await getOperatorChangeRequests(currentParkingLot.value.id)
    if (response.success) {
      requestHistory.value = response.data.list || []
    }
  } catch (error) {
    console.error('加载申请记录失败:', error)
    // 不显示错误提示，因为可能是首次使用没有记录
  }
}

const getRequestTypeText = (type) => {
  const typeMap = {
    'close_dates': '停用申请',
    'activate': '启用申请',
    'modify_comprehensive': '停车场信息编辑',
    'modify_spaces': '车位数修改',
    'modify_images': '图片修改',
    'modify_info': '基本信息修改'
  }
  return typeMap[type] || '未知'
}

const getStatusText = (status) => {
  const statusMap = {
    'pending': '待处理',
    'approved': '已批准',
    'rejected': '已拒绝'
  }
  return statusMap[status] || '未知'
}

const formatDate = (dateString) => {
  try {
    const date = new Date(dateString)
    return date.toLocaleString('zh-CN')
  } catch (error) {
    return '格式错误'
  }
}

/**
 * 加载停车场分类数据
 */
const loadCategories = async () => {
  try {
    const response = await get('/api/parking/categories')
    if (response.success) {
      categories.value = response.data || []
    }
  } catch (error) {
    console.error('加载分类数据失败:', error)
    // 如果加载失败，不影响其他功能
  }
}

/**
 * 切换服务设施选项
 */
const toggleFacility = (facilityKey) => {
  const facilities = [...editData.value.service_facilities]
  const index = facilities.indexOf(facilityKey)
  
  if (index > -1) {
    // 已存在，移除
    facilities.splice(index, 1)
  } else {
    // 不存在，添加
    facilities.push(facilityKey)
  }
  
  editData.value.service_facilities = facilities
}

/**
 * 获取分类名称
 */
const getCategoryName = (categoryId) => {
  if (!categoryId) return '未分类'
  const category = categories.value.find(cat => cat.id === categoryId)
  return category ? category.name : '未知分类'
}

/**
 * 获取分类索引
 */
const getCategoryIndex = (categoryId) => {
  if (!categoryId) return 0
  const index = categories.value.findIndex(cat => cat.id === categoryId)
  return index > -1 ? index : 0
}

/**
 * 选择分类
 */
const selectCategory = (event) => {
  const index = event.detail.value
  if (index >= 0 && index < categories.value.length) {
    editData.value.category_id = categories.value[index].id
  } else {
    editData.value.category_id = null
  }
}

// 生命周期
onMounted(async () => {
  await Promise.all([
    loadParkingLotInfo(),
    loadRequestHistory(),
    loadCategories()
  ])
})
</script>

<style scoped>
.change-request-page {
  padding: 20rpx;
  background: #f8f9fa;
  min-height: 100vh;
}

.page-header {
  text-align: center;
  margin-bottom: 40rpx;
}

.page-title {
  font-size: 36rpx;
  font-weight: bold;
  color: #333;
  display: block;
  margin-bottom: 10rpx;
}

.page-desc {
  font-size: 28rpx;
  color: #666;
  display: block;
}

.request-type-section,
.form-section,
.submit-section,
.history-section {
  background: white;
  border-radius: 16rpx;
  padding: 30rpx;
  margin-bottom: 20rpx;
}

.section-title {
  font-size: 32rpx;
  font-weight: bold;
  color: #333;
  display: block;
  margin-bottom: 20rpx;
}

.type-options {
  display: flex;
  flex-direction: column;
  gap: 20rpx;
}

.type-option {
  padding: 30rpx;
  border: 2rpx solid #e0e0e0;
  border-radius: 12rpx;
  transition: all 0.3s;
}

.type-option.active {
  border-color: #409eff;
  background: #f0f8ff;
}

.type-name {
  font-size: 30rpx;
  font-weight: bold;
  color: #333;
  display: block;
  margin-bottom: 10rpx;
}

.type-desc {
  font-size: 26rpx;
  color: #666;
  display: block;
}

.add-date-btn {
  background: #409eff;
  color: white;
  border: none;
  padding: 20rpx 40rpx;
  border-radius: 8rpx;
  margin-bottom: 20rpx;
}

.date-item {
  display: flex;
  align-items: center;
  gap: 20rpx;
  margin-bottom: 20rpx;
  padding: 20rpx;
  background: #f8f9fa;
  border-radius: 8rpx;
}

.date-input {
  flex: 1;
  padding: 20rpx;
  border: 1rpx solid #ddd;
  border-radius: 8rpx;
  background: white;
}

.reason-input {
  flex: 2;
  padding: 20rpx;
  border: 1rpx solid #ddd;
  border-radius: 8rpx;
}

.remove-btn {
  background: #f56c6c;
  color: white;
  border: none;
  padding: 15rpx 30rpx;
  border-radius: 8rpx;
}

.spaces-form {
  display: flex;
  flex-direction: column;
  gap: 20rpx;
}

.current-spaces,
.new-spaces {
  display: flex;
  align-items: center;
  gap: 20rpx;
}

.spaces-input {
  flex: 1;
  padding: 20rpx;
  border: 1rpx solid #ddd;
  border-radius: 8rpx;
}

.image-list {
  display: flex;
  flex-wrap: wrap;
  gap: 20rpx;
}

.image-item {
  position: relative;
}

.preview-image {
  width: 200rpx;
  height: 200rpx;
  border-radius: 8rpx;
}

.remove-image-btn {
  position: absolute;
  top: -10rpx;
  right: -10rpx;
  background: #f56c6c;
  color: white;
  border: none;
  border-radius: 50%;
  width: 40rpx;
  height: 40rpx;
  font-size: 24rpx;
}

.upload-btn {
  width: 200rpx;
  height: 200rpx;
  border: 2rpx dashed #ddd;
  border-radius: 8rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 60rpx;
  color: #999;
}

.info-form {
  display: flex;
  flex-direction: column;
  gap: 30rpx;
}

.form-item {
  display: flex;
  flex-direction: column;
  gap: 10rpx;
}

.label {
  font-size: 28rpx;
  color: #333;
  font-weight: bold;
}

.info-input,
.info-textarea {
  padding: 20rpx;
  border: 1rpx solid #ddd;
  border-radius: 8rpx;
}

.info-textarea {
  min-height: 120rpx;
}

.reason-textarea {
  width: 100%;
  min-height: 200rpx;
  padding: 20rpx;
  border: 1rpx solid #ddd;
  border-radius: 8rpx;
  resize: vertical;
}

.submit-btn {
  width: 100%;
  background: #409eff;
  color: white;
  border: none;
  padding: 30rpx;
  border-radius: 12rpx;
  font-size: 32rpx;
  font-weight: bold;
}

.submit-btn:disabled {
  background: #ccc;
}

.empty-history {
  text-align: center;
  color: #999;
  padding: 60rpx;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 20rpx;
}

.history-item {
  padding: 30rpx;
  background: #f8f9fa;
  border-radius: 12rpx;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15rpx;
}

.history-type {
  font-size: 28rpx;
  font-weight: bold;
  color: #333;
}

.history-status {
  font-size: 24rpx;
  padding: 8rpx 16rpx;
  border-radius: 20rpx;
}

.history-status.pending {
  background: #fff3cd;
  color: #856404;
}

.history-status.approved {
  background: #d4edda;
  color: #155724;
}

.history-status.rejected {
  background: #f8d7da;
  color: #721c24;
}

.history-reason {
  font-size: 26rpx;
  color: #666;
  display: block;
  margin-bottom: 10rpx;
}

.history-time {
  font-size: 24rpx;
  color: #999;
  display: block;
  margin-bottom: 10rpx;
}

.admin-comment {
  font-size: 26rpx;
  color: #409eff;
  display: block;
  background: #f0f8ff;
  padding: 15rpx;
  border-radius: 8rpx;
  margin-top: 10rpx;
}

/* 停用申请警告样式 */
.close-warning {
  display: flex;
  align-items: flex-start;
  gap: 20rpx;
  padding: 30rpx;
  background: #fff3cd;
  border: 2rpx solid #ffeaa7;
  border-radius: 12rpx;
  margin-bottom: 20rpx;
}

.warning-icon {
  font-size: 40rpx;
  flex-shrink: 0;
}

.warning-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10rpx;
}

.warning-title {
  font-size: 30rpx;
  font-weight: bold;
  color: #856404;
  display: block;
}

.warning-desc {
  font-size: 26rpx;
  color: #856404;
  display: block;
  line-height: 1.4;
}

/* 价格规则样式 */
.price-rules-form {
  display: flex;
  flex-direction: column;
  gap: 20rpx;
}

.price-input {
  width: 100%;
  height: 80rpx;
  padding: 0 20rpx;
  border: 2rpx solid #ddd;
  border-radius: 8rpx;
  font-size: 28rpx;
  background: white;
}

.price-input:focus {
  border-color: #007aff;
  outline: none;
}

/* 营业执照样式 */
.business-form {
  display: flex;
  flex-direction: column;
  gap: 20rpx;
}

.license-upload-section {
  display: flex;
  flex-direction: column;
  gap: 15rpx;
}

.current-license {
  display: flex;
  flex-wrap: wrap;
  gap: 15rpx;
}

/* 启用申请信息样式 */
.activate-info {
  display: flex;
  align-items: flex-start;
  gap: 20rpx;
  padding: 30rpx;
  background: #d4edda;
  border: 2rpx solid #c3e6cb;
  border-radius: 12rpx;
  margin-bottom: 20rpx;
}

.info-icon {
  font-size: 40rpx;
  flex-shrink: 0;
}

.info-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10rpx;
}

.info-title {
  font-size: 30rpx;
  font-weight: bold;
  color: #155724;
  display: block;
}

.info-desc {
  font-size: 26rpx;
  color: #155724;
  display: block;
  line-height: 1.4;
}

/* 统一编辑样式 */
.info-group {
  margin-bottom: 30rpx;
  padding: 20rpx;
  background: #f8f9fa;
  border-radius: 12rpx;
}

.group-title {
  font-size: 30rpx;
  font-weight: bold;
  color: #333;
  display: block;
  margin-bottom: 20rpx;
  padding-bottom: 10rpx;
  border-bottom: 2rpx solid #e0e0e0;
}

.current-value {
  font-size: 28rpx;
  color: #666;
  padding: 20rpx;
  background: #fff;
  border-radius: 8rpx;
  border: 1rpx solid #e0e0e0;
}

.unit {
  font-size: 28rpx;
  color: #666;
  margin-left: 10rpx;
}

.upload-tip {
  font-size: 26rpx;
  color: #666;
  display: block;
  margin-bottom: 15rpx;
}

.current-images {
  display: flex;
  flex-wrap: wrap;
  gap: 20rpx;
  margin-bottom: 20rpx;
}

.image-limit-tip {
  font-size: 24rpx;
  color: #999;
  text-align: center;
  margin-top: 15rpx;
  display: block;
}

/* 新增的样式 */
/* 分类选择器 */
.picker-display {
  padding: 20rpx;
  background: #fff;
  border: 1rpx solid #e0e0e0;
  border-radius: 8rpx;
  color: #333;
  font-size: 28rpx;
}

/* 距离信息表单 */
.distance-form {
  display: flex;
  flex-direction: column;
  gap: 20rpx;
}

.distance-input {
  flex: 1;
  padding: 20rpx;
  border: 1rpx solid #e0e0e0;
  border-radius: 8rpx;
  background: #fff;
  font-size: 28rpx;
}

/* 服务设施网格 */
.facilities-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 15rpx;
  margin-top: 15rpx;
}

.facility-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 150rpx;
  height: 120rpx;
  padding: 15rpx;
  background: #f8f9fa;
  border: 2rpx solid #e0e0e0;
  border-radius: 12rpx;
  transition: all 0.3s;
}

.facility-item.active {
  background: #e3f2fd;
  border-color: #2196f3;
}

.facility-icon {
  font-size: 32rpx;
  margin-bottom: 8rpx;
}

.facility-name {
  font-size: 24rpx;
  color: #666;
  text-align: center;
  line-height: 1.2;
}

.facility-item.active .facility-name {
  color: #2196f3;
  font-weight: bold;
}

/* 价格规则新样式 */
.billing-mode-section {
  margin-bottom: 30rpx;
}

.mode-options {
  display: flex;
  gap: 20rpx;
  margin-top: 20rpx;
}

.mode-option {
  flex: 1;
  padding: 20rpx;
  background: #f8f9fa;
  border: 2rpx solid #ddd;
  border-radius: 8rpx;
  text-align: center;
  font-size: 28rpx;
  color: #666;
}

.mode-option.active {
  background: #007aff;
  border-color: #007aff;
  color: white;
}

.indoor-outdoor-section {
  margin-bottom: 30rpx;
}

.switch-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20rpx 0;
}

.unified-pricing,
.separate-pricing {
  margin-bottom: 30rpx;
}

.indoor-pricing,
.outdoor-pricing {
  margin-bottom: 40rpx;
  padding: 30rpx;
  background: #f8f9fa;
  border-radius: 12rpx;
}

.daily-prices-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20rpx;
  margin-top: 20rpx;
}

.price-item {
  display: flex;
  flex-direction: column;
  gap: 10rpx;
}

.price-label {
  font-size: 24rpx;
  color: #666;
}

.price-unit {
  font-size: 24rpx;
  color: #666;
  margin-left: 10rpx;
}

.after-7-section {
  margin-top: 30rpx;
  padding-top: 30rpx;
  border-top: 2rpx solid #eee;
}

.sub-title {
  font-size: 30rpx;
  font-weight: 600;
  color: #333;
  margin-bottom: 20rpx;
  display: block;
}

/* 营业资料新样式 */
.document-section {
  margin-bottom: 40rpx;
}

.document-upload {
  margin-top: 20rpx;
}

.upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 200rpx;
  border: 2rpx dashed #ddd;
  border-radius: 12rpx;
  background: #f8f9fa;
  color: #666;
}

.upload-icon {
  font-size: 60rpx;
  margin-bottom: 15rpx;
}

.upload-text {
  font-size: 28rpx;
  margin-bottom: 10rpx;
}

.upload-tip {
  font-size: 24rpx;
  color: #999;
}

.document-preview {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20rpx;
  background: white;
  border: 2rpx solid #eee;
  border-radius: 8rpx;
  margin-bottom: 15rpx;
}

.document-info {
  flex: 1;
}

.document-name {
  font-size: 28rpx;
  color: #333;
  display: block;
  margin-bottom: 5rpx;
}

.document-size {
  font-size: 24rpx;
  color: #999;
}

.document-actions {
  display: flex;
  gap: 15rpx;
}

.action-btn {
  padding: 10rpx 20rpx;
  border-radius: 6rpx;
  font-size: 24rpx;
  border: none;
}

.view-btn {
  background: #007aff;
  color: white;
}

.remove-btn {
  background: #ff3b30;
  color: white;
}

.document-list {
  display: flex;
  flex-direction: column;
  gap: 15rpx;
}

.add-more-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 80rpx;
  border: 2rpx dashed #007aff;
  border-radius: 8rpx;
  color: #007aff;
  font-size: 28rpx;
  background: #f0f8ff;
}

.business-tip {
  margin-top: 20rpx;
  padding: 15rpx;
  background: #fff3cd;
  border-radius: 8rpx;
  font-size: 24rpx;
  color: #856404;
}
</style>